﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Reflection;

namespace EyeOpen.Validation
{
    /// <summary>
    /// Returns a concrete validator using a particular logic.
    /// </summary>
    public class ValidatorFactory : IValidationProviderFactory
    {
        static Assembly activeValidationProvider = null;
        static IValidationProviderFactory validatorProviderFactory = null;
        
        static ValidatorFactory() {
            string validationProviderName = ConfigurationManager.AppSettings["ValidationProvider"];
            string validationProviderFactory = ConfigurationManager.AppSettings["ValidationProviderFactory"];
            activeValidationProvider = Assembly.Load(validationProviderName);
            validatorProviderFactory = (IValidationProviderFactory)activeValidationProvider.CreateInstance(validationProviderFactory);
        }

        /// <summary>
        /// Gets the validator.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public IEntityValidator GetValidator<T>()
        {
            return validatorProviderFactory.GetValidator<T>();
        }
    }
}
